/// <license>
/// Copyright (c) 2002-2008, DotNetNuke Corporation
/// All rights reserved
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
/// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
/// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
/// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
/// of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
/// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
/// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
/// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
/// DEALINGS IN THE SOFTWARE.
/// </license>

#region Using Statements

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Web.UI.WebControls;
using System.Xml.Serialization;

using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.UI.WebControls;

using Constants = DotNetNuke.Modules.Articles.Common.Constants;
using DotNetNuke.ModuleToolkit.Framework;

#endregion

namespace DotNetNuke.Modules.Articles.Framework
{
    /// -----------------------------------------------------------------------------
    /// <summary>
    /// The ArticleInfo Class provides the Article Business Object
    /// </summary>
    /// <history>
    /// 	[cnurse]	01/31/2006	Created
    /// </history>
    /// -----------------------------------------------------------------------------
    [XmlRoot("article")]
    public class ArticleInfo :
        VersionedEntityBase, 
        IHydratable
    {

        #region Private Members

        //Primary Key
        private int _ArticleId;

        //Other Keys
        private int _SectionId;

        //Other Fields
        private string _Abstract;
        private int _AbstractImage;
        private string _Author;
        private string _Body;
        private string _SubTitle;
        private string _Title;

        #endregion

        #region Public Properties

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets and sets the Abstract of the Article
        /// </summary>
        /// <history>
        /// 	[cnurse]	01/31/2006	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        [Bindable(false),
        Category(Constants.CATEGORY_Abstract),
        ControlStyle("", "500px", "200px"),
        Editor("DotNetNuke.UI.WebControls.DNNRichTextEditControl, DotNetNuke", "DotNetNuke.UI.WebControls.EditControl, DotNetNuke"),
        LabelMode(LabelMode.Top),
        SortOrder(7), 
        XmlElement("abstract")]
        public string Abstract
        {
            get { return _Abstract; }
            set { _Abstract = value; }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets and sets the Abstract Image of the Article
        /// </summary>
        /// <history>
        /// 	[cnurse]	01/31/2006	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        [Bindable(false),
        Category(Constants.CATEGORY_Abstract),
        Editor("DotNetNuke.ModuleToolkit.Controls.ImageEditControl, DotNetNuke.ModuleToolkit", "DotNetNuke.UI.WebControls.EditControl"),
        SortOrder(6), 
        XmlElement("abstractImage")]
        public int AbstractImage
        {
            get { return _AbstractImage; }
            set { _AbstractImage = value; }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets and sets the Id of the Article
        /// </summary>
        /// <history>
        /// 	[cnurse]	01/31/2006	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        [Browsable(false), XmlIgnore()]
        public int ArticleId
        {
            get { return _ArticleId; }
            set { _ArticleId = value; }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets and sets the Author of the Article
        /// </summary>
        /// <history>
        /// 	[cnurse]	01/31/2006	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        [Bindable(false),
        Category(Constants.CATEGORY_Basic),
        SortOrder(3), 
        XmlElement("author")]
        public string Author
        {
            get { return _Author; }
            set { _Author = value; }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets and sets the Body of the Article
        /// </summary>
        /// <history>
        /// 	[cnurse]	01/31/2006	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        [Bindable(false),
        Category(Constants.CATEGORY_Article),
        ControlStyle("", "500px", "300px"),
        Editor("DotNetNuke.UI.WebControls.DNNRichTextEditControl, DotNetNuke", "DotNetNuke.UI.WebControls.EditControl, DotNetNuke"),
        LabelMode(LabelMode.Top),
        SortOrder(8),
        XmlElement("abstract")]
        public string Body
        {
            get { return _Body; }
            set { _Body = value; }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets and sets the Id of the Section
        /// </summary>
        /// <history>
        /// 	[cnurse]	01/31/2006	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        [Bindable(false),
        Category(Constants.CATEGORY_Basic),
        Editor("DotNetNuke.Modules.Articles.UI.Editors.SectionEditControl, DotNetNuke.Modules.Articles", "DotNetNuke.UI.WebControls.EditControl"),
        SortOrder(2), 
        XmlIgnore()]
        public int SectionId
        {
            get { return _SectionId; }
            set { _SectionId = value; }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets and sets the SubTitle of the Article
        /// </summary>
        /// <history>
        /// 	[cnurse]	01/31/2006	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        [Bindable(false),
        Category(Constants.CATEGORY_Basic),
        ControlStyle("NormalTextBox", "300px"),
        SortOrder(1), 
        XmlElement("subTitle")]
        public string SubTitle
        {
            get { return _SubTitle; }
            set { _SubTitle = value; }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets and sets the Title of the Article
        /// </summary>
        /// <history>
        /// 	[cnurse]	01/31/2006	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        [Bindable(false),
        Category(Constants.CATEGORY_Basic),
        ControlStyle("NormalTextBox", "300px", "30px"),
        Editor("DotNetNuke.UI.WebControls.MultiLineTextEditControl, DotNetNuke", "DotNetNuke.UI.WebControls.EditControl, DotNetNuke"),
        Required(true),
        SortOrder(0), 
        XmlElement("title")]
        public string Title
        {
            get { return _Title; }
            set { _Title = value; }
        }

        #endregion

        #region IHydratable Members

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Gets and sets the KeyID of the Article
        /// </summary>
        /// <remarks>The KeyID is the unique identifier, used by the CBO class to build
        /// a Dictionary of Articles</remarks>
        /// <history>
        /// 	[cnurse]	07/04/2007	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        [Browsable(false),
        XmlIgnore()]
        public int KeyID
        {
            get { return ArticleId; }
            set { ArticleId = value; }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Hydrates an Article from a DataReader representing the Article
        /// </summary>
        /// <param name="source">The Data Reader containing the values to use to fill the Article.</param>
        /// <history>
        /// 	[cnurse]	12/22/2006	created
        /// </history>
        /// -----------------------------------------------------------------------------
        public void Fill(IDataReader source)
        {
            //Hydrate the EntityBase Properties
            base.FillInternal(source);

            ArticleId = Convert.ToInt32(Null.SetNull(source["ArticleID"], ArticleId));
            SectionId = Convert.ToInt32(Null.SetNull(source["SectionID"], SectionId));
            Title = Convert.ToString(Null.SetNull(source["Title"], Title));
            SubTitle = Convert.ToString(Null.SetNull(source["SubTitle"], SubTitle));
            Abstract = Convert.ToString(Null.SetNull(source["Abstract"], Abstract));
            AbstractImage = Convert.ToInt32(Null.SetNull(source["AbstractImage"], AbstractImage));
            Author = Convert.ToString(Null.SetNull(source["Author"], Author));
            Body = Convert.ToString(Null.SetNull(source["Body"], Body));
        }

        #endregion

    }
}
